package com.sunnyebuy.merchant.service.impl;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sunnyebuy.merchant.dao.CountryDAO;
import com.sunnyebuy.merchant.service.CountryService;

/**
 * <p>
 * Title: CountryServiceImpl.java
 * </p>
 * 
 * <p>
 * Description: com.sunnyebuy.merchant.service.impl
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2008-2011 All rights reserved.
 * </p>
 * 
 * <p>
 * Created: 2011-12-28 上午11:19:57
 * </p>
 * 
 * @author Wenzhong Gu
 * 
 * @version 1.0
 */
@Service(value = "countryService")
public class CountryServiceImpl implements CountryService {

	private static final Logger log = LoggerFactory.getLogger(CountryServiceImpl.class);

	@Resource
	private CountryDAO countryDAO;

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	@Cacheable(value = "country", key = "countries")
	public Map<String, String> findAllCountries() {
		try {
			List<?> countries = countryDAO.findAllCountries();
			Map<String, String> countryMap = new TreeMap<String, String>();
			String[] country = null;
			for (int i = 0; i < countries.size(); i++) {
				country = (String[]) countries.get(i);
				countryMap.put(country[0], country[1]);
			}
			return countryMap;
		} catch (Exception e) {
			log.error("=== method : findAllCounties ERROR ==={}" + e.getStackTrace());
			return null;
		}
	}

}